﻿using UnityEngine;
using System.Collections;

/// <summary>
/// 鼠标控制器
/// </summary>
public class MouseController : PlatformController
{	
	/// 鼠标枚举
	enum MouseTypeEnum
	{
		LEFT = 0
	}

	/// <summary>
	/// 缩放距离
	/// </summary>
	private float scrollDistance;

	/// <summary>
	/// 鼠标按住状态
	/// </summary>
	private bool mousePressStatus; 
	void Update()
	{
		// 按下鼠标、轴
		if (Input.GetMouseButtonDown ((int)MouseTypeEnum.LEFT)) 
		{
			this.mousePressStatus = true;
			// 触发开始回调函数
			if(mInput != null) mInput.OnBegin(Input.mousePosition);
        }
		// 松开鼠标、轴
		if (Input.GetMouseButtonUp ((int)MouseTypeEnum.LEFT)) 
		{
			this.mousePressStatus = false;
            // 触发结束回调函数
            if (mInput != null) mInput.OnEnd(Input.mousePosition);
        }
		// 如果鼠标在按住状态
		if (this.mousePressStatus) 
		{
            // 触发移动回调函数
            if (mInput != null) mInput.OnMove(Input.mousePosition, new Vector2(Input.GetAxis("Mouse X") * 10 , Input.GetAxis("Mouse Y") * 10 ));
        }
		// 鼠标滚轮拉近拉远
		this.scrollDistance = Input.GetAxis ("Mouse ScrollWheel");
        // 触发缩放回调函数
        if (mInput != null) mInput.OnScale(Input.mousePosition,this.scrollDistance);

        // 触发每帧执行更新
        if (mInput != null) mInput.OnUpdate();
    }
}
